#!/bin/bash

set -ux

# # 如果桌面环境未安装时，需要提前安装好。已安装请忽略
# dnf groupinstall "Server with GUI"

# 安装VNC Server
dnf install tigervnc-server tigervnc-server-module -y &&
  dnf clean all

# 修改配置
cat >> /etc/tigervnc/vncserver.users << EOF
:1=root
EOF

# 启动服务 端口号为5900 + 1
vncserver :1

# 重新加载配置
systemctl daemon-reload

# 启动并添加开机自启服务
systemctl enable vncserver@:1.service --now
systemctl start vncserver@:1.service

# 开放端口
firewall-cmd --zone=public --add-port=5901/tcp --permanent &&
  firewall-cmd --reload

# 验证运行状态
systemctl status vncserver@:1.service
